// components/storeList/storeList.js
const app = getApp();
import { getDistance } from "../../utils/jobUtil";

Component({

  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    storeList:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getStoreList(requestData){

      app.$loadingUtil.showLoading('加载中');

      let that = this;
      let wantWorkArea = '';

      if (requestData) {
        wantWorkArea = requestData.wantWorkArea
      }
      app.$http.getStoreList(requestData).then(res=>{
        wx.stopPullDownRefresh();
        app.$loadingUtil.hideLoading();
        let storeList = [];
        res.forEach(item=>{
          let storeInfo = {
            storeId:item.storeId,
            area:item.area,
            city:item.city,
            hyNames:item.hyNames,
            remainRecruitCount:item.remainRecruitCount,
            storeName:item.storeName,
            distance: wantWorkArea && "距离" + wantWorkArea + getDistance(item.distance),
          }
          storeList.push(storeInfo);
        });
        that.setData({
          storeList:storeList
        })
      })
    },

    goStoreDetail(e){
      const storeId = e.currentTarget.dataset.storeid;
      getApp().$routes.goTo(getApp().$routes.my_store, {id:storeId});
    }
  }
})
